#include "MainFrame/MenuBar/MenuBar.h"
#include "MainFrame/MenuBar/FileMenuList.h"
#include "MainFrame/MenuBar/EditMenuList.h"
#include "MainFrame/MenuBar/ImageMenuList.h"
#include "MainFrame/MenuBar/ColorsMenuList.h"
#include "MainFrame/MenuBar/FiltersMenuList.h"
#include "MainFrame/MenuBar/HelpMenuList.h"
#include <QEvent>

MenuBar::MenuBar(QWidget *parent) :
    QMenuBar(parent),
    m_pFileMenuList(nullptr),
    m_pEditMenuList(nullptr),
    m_pImageMenuList(nullptr),
    m_pColorsMenuList(nullptr),
    m_pFiltersMenuList(nullptr),
    m_pHelpMenuList(nullptr)
{
    initMenuBar();
}

MenuBar::~MenuBar()
{

}

void MenuBar::changeEvent(QEvent *event)
{
    QWidget::changeEvent(event);
    switch (event->type())
    {
    case QEvent::LanguageChange:
        initTrans();
        break;
    default:
        break;
    }
}

void MenuBar::initTrans()
{
    m_pFileMenuList->setTitle(tr("File"));
    m_pEditMenuList->setTitle(tr("Edit"));
    m_pImageMenuList->setTitle(tr("Image"));
    m_pColorsMenuList->setTitle(tr("Colors"));
    m_pFiltersMenuList->setTitle(tr("Filters"));
    m_pHelpMenuList->setTitle(tr("Help"));
}

void MenuBar::initMenuBar()
{
    addFileMenuList();
    addEditMenuList();
    addImageMenuList();
    addColorsMenuList();
    addFiltersMenuList();
    addHelpMenuList();
}

void MenuBar::addFileMenuList()
{
    m_pFileMenuList = new FileMenuList("File", this);

    connect(m_pFileMenuList, SIGNAL(closeMainFrame()),
            this, SIGNAL(closeMainFrame()));
    connect(m_pFileMenuList, SIGNAL(openImageSignal(QString)),
            this, SIGNAL(openImageSignal(QString)));
    this->addMenu(m_pFileMenuList);
}

void MenuBar::addEditMenuList()
{
    m_pEditMenuList = new EditMenuList("Edit", this);
    this->addMenu(m_pEditMenuList);
}

void MenuBar::addImageMenuList()
{
    m_pImageMenuList = new ImageMenuList("Image", this);
    this->addMenu(m_pImageMenuList);
}

void MenuBar::addColorsMenuList()
{
    m_pColorsMenuList = new ColorsMenuList("Colors", this);
    this->addMenu(m_pColorsMenuList);
}

void MenuBar::addFiltersMenuList()
{
    m_pFiltersMenuList = new FiltersMenuList("Filters", this);
    this->addMenu(m_pFiltersMenuList);
}

void MenuBar::addHelpMenuList()
{
    m_pHelpMenuList = new HelpMenuList("Help", this);
    this->addMenu(m_pHelpMenuList);
}
